#include <iostream>
#include <sys/socket.h>
#include <cstring>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>

using namespace std;

int main()
{
    // 创建文件描述符
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);

    // 绑定IP和端口
    struct sockaddr_in localAddress;
    memset(&localAddress, 0, sizeof(localAddress));
    localAddress.sin_family = AF_INET;
    localAddress.sin_port = htons(8080); // 转为大端
    const char *privateIp = "172.17.0.12";
    inet_pton(AF_INET, privateIp, (void *)&localAddress.sin_addr.s_addr);

    bind(sockfd, (struct sockaddr *)&localAddress, sizeof(localAddress));

    // 设置监听
    listen(sockfd, 10);

    int connfd = accept(sockfd, NULL, NULL);
    cout << "connfd:" << connfd << endl;

    char buffer[32] = { 0 };
    while (1)
    {
        // 查看上报数据
        read(connfd, buffer, sizeof(buffer));
        cout << buffer << endl;
    }
    
    return 0;
}